<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sample1: Ext.ux.google.map.View / Ext.ux.google.search.*</title>
    <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
    <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/ext-all-debug.js"> </script>

    <script type="text/javascript" src="../../Ext.ux.google.Loader.js"></script>
    <script type="text/javascript" src="../../search/Ext.ux.google.search.Proxy.js"></script>
    <script type="text/javascript" src="../../search/Ext.ux.google.search.Reader.js"></script>
    <script type="text/javascript" src="../../search/Ext.ux.google.search.Store.js"></script>

    <script type="text/javascript">
      Ext.onReady(function(){
        var tpl = new Ext.XTemplate(
          '<tpl for=".">',
              '<div class="selector">',
              '<a href="{url}">{title}</a><br />',
              '<span>{content}</span></div><br />',
          '</tpl>'
        );

        var store = new Ext.ux.google.search.Store({
          proxy: {
            apiKey: 'ABQIAAAA3HEaipgCJKasbKv8S1gdbBQRwYGrJs7PTc23wXYGvCkgV6rZmhSdnrJh9Xe77AdhJyXWHiwWb8t7pA'
          }
        });

        var doSearch = function(query){
          if(!query) return;

          store.load({
            params: {
              query: query,
              start: 0
            }
          });
        };

        new Ext.Viewport({
          layout: 'border',
          items: [{
            region: 'north',
            height: 40,
            layout: 'table',
            items: [{
              xtype: 'textfield',
              id: 'querystr',
              enableKeyEvents: true,
              listeners: {
                'keypress': function(t, e){
                  if(e.getKey() == 13)
                    doSearch(Ext.getCmp('querystr').getValue());
                }
              }
            }]
          },{
            region: 'center',
            xtype: 'panel',
            layout: 'fit',
            items: [{
              xtype: 'dataview',
              store: store,
              tpl: tpl,
              itemSelector: 'div.selector'
            }],
            bbar: new Ext.PagingToolbar({
              id: 'ptbar',
              store: store,
              pageSize: store.getResultSetSize()
            })
          }]
        });
      
        if(!store.isReady()){
          store.on('searchapiinitialized',function(){
            Ext.getCmp('ptbar').pageSize = store.getResultSetSize();
          });
        }
      });  
    </script>
</head>
<body>
</body>
</html>
